#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

bool isInterleave(string s1, string s2, string s3) {
    int n = s1.size(), m = s2.size();
    if (n + m != s3.size())  return false;
    vector<vector<bool>> f(n + 1, vector<bool>(m + 1));
    f[0][0] = true;
    s1 = ' ' + s1, s2 = ' ' + s2, s3 = ' ' + s3;
    for (int i = 1; i <= n; i++)
        if (s1[i] == s3[i])
            f[i][0] = true;
        else break;
    for (int i = 1; i <= m; i++)
        if (s2[i] == s3[i])
            f[0][i] = true;
        else break;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            int k = i + j;
            if (s3[k] == s1[i])  f[i][j] = f[i - 1][j];
            if (s3[k] == s2[j]) f[i][j] = f[i][j] || f[i][j - 1];
        }

    return  f[n][m];
}

int minimumDeleteSum(string s1, string s2) {
    int n = s1.size(), m = s2.size();
    vector<vector<int>> f(n + 1, vector<int>(m + 1));

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            f[i][j] = max(f[i - 1][j], f[i][j - 1]);
            if (s1[i - 1] == s2[j - 1])
                f[i][j] = max(f[i][j], f[i - 1][j - 1] + s1[i - 1]);
        }

    int sum = 0;
    for (auto c : s1)
        sum += c;
    for (auto c : s2)
        sum += c;
    return sum - f[n][m] - f[n][m];
}